#if !NETCF
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

namespace TelnetExpect
{
    /// <summary>
    /// A concrete implementation of <see cref="T:TelnetExpect.TerminalAnsiTelnetHandlerBase"/>
    /// for <see cref="T:System.Console">System.Console</see>.
    /// For NAWS uses
    /// <see cref="P:System.Console.WindowWidth">Console.WindowWidth</see> etc,
    /// and disables negotiation if not running in console.
    /// </summary>
    public class ConsoleTerminalAnsiTelnetHandler : TerminalAnsiTelnetHandlerBase
    {
        /// <summary>
        /// Initializes an instance of class <see cref="T:ConsoleTerminalAnsiTelnetHandler"/>.
        /// </summary>
        public ConsoleTerminalAnsiTelnetHandler()
        {
        }

        /// <exclude/>
        protected internal override void Init()
        {
            base.Init();
            Debug.Assert(Telnet.GetLocalMode(TelnetOption.TerminalType), "Base should enabled TerminalType");
            Debug.Assert(Telnet.GetLocalMode(TelnetOption.NegotiateAboutWindowSize), "Base should enabled NAWS");
            try {
                Console.CursorLeft = Console.CursorLeft;
                //
                // Now we've tested we're not redirected to a file etc!
            } catch (IOException) {
                TraceWriteLine("Disabling Telnet TerminalType (ANSI) as not on a Console.");
                Telnet.SetLocalMode(TelnetOption.TerminalType, false);
                Telnet.SetLocalMode(TelnetOption.NegotiateAboutWindowSize, false);
            }
        }

        /// <summary>
        /// Provides window size using <see cref="P:System.Console.WindowWidth">Console.WindowWidth</see> etc.
        /// </summary>
        /// -
        /// <param name="width">Returns the result of
        /// <see cref="P:System.Console.WindowWidth">Console.WindowWidth</see>.
        /// </param>
        /// <param name="height">Returns the result of
        /// <see cref="P:System.Console.WindowHeight">Console.WindowHeight</see>.
        /// </param>
        protected override void GetWindowSize(out int width, out int height)
        {
            width = Console.WindowWidth;
            height = Console.WindowHeight;
        }

    }

}
#endif
